

import socket


# 1.创建一个socket连接
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 2.绑定IP端口
sk.bind(('127.0.0.1', 8888))

# 3.监听连接个数
sk.listen(5)

print("服务端启动成功")

# 4.等待连接
clientSocket, clientAddress = sk.accept()

print("客户端连接成功:" + str(clientSocket))

data = []
while True:
    d = clientSocket.recv(1024)

    data.append(d)

    datastr = (b''.join(data)).decode('utf-8')

    print("收到" + str(clientSocket) + '的数据datastr =  ', datastr)

    clientSocket.send("收到".encode("utf-8"))


